package LC;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName LC93
 * @Description: TODO
 * @Author hl
 * @Date 2020/9/15
 * @Version V1.0
 **/
public class LC93 {


    public static void main(String[] args) {



      List<String> list=restoreIpAddresses("25525511135");
      for(int i=0;i<list.size();i++){
          System.out.println(list.get(i));
      }


    }
    public static List<String> restoreIpAddresses(String s) {
        List<String> res=new ArrayList<>();
        if(s==null||s.length()==0){
            return res;
        }
       StringBuffer str=new StringBuffer();
       find(0,s,res,str);
       return  res;
    }

    private static void find(int i, String s, List<String> res,StringBuffer str) {
        if(i==4||s.length()==0){
            if(i==4&&s.length()==0){
                res.add(str.toString());
            }
            return;
        }
        for(int j=0;j<s.length()&&j<=2;j++){
            if(j!=0&&s.charAt(0)=='0'){
                break;
            }
            String part=s.substring(0,j+1);
          if(Integer.valueOf(part)<=255){
              if(str.length()!=0){
                  part="."+part;
              }
              str.append(part);
              find(i+1,s.substring(j+1),res,str);
              str.delete(str.length()-part.length(),str.length());

          }

        }

    }
}
